package com.imooc.miaosha.filter;

import com.imooc.miaosha.util.ServletUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 模块描述: <br>
 * ()
 *
 * @Author: Mr. xyb
 * @Date: 2019/4/17 10:41
 * @since: 1.8.0
 * @version: 1.0.0
 */
public class RequestDataFilter implements Filter {

    private static final Log log = LogFactory.getLog(RequestDataFilter.class);

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;

        ServletUtils.setRequest(request);
        ServletUtils.setResponse((HttpServletResponse) servletResponse);
        try {
            filterChain.doFilter(servletRequest, servletResponse);
        } finally {
            ServletUtils.setRequest(null);
            ServletUtils.setResponse(null);
        }
    }

    @Override
    public void destroy() {

    }
}
